#include "thread.h"

#define thread_log(fmt,...)\
            do {\
                printf(fmt,##__VA_ARGS__);\
            } while(0)

thread::thread(func fun, void *args, void **ret) {
    mFun = fun;
    mArgs = args;
    mRet = ret;
}

thread::~thread() {

}

int thread::init() {
    int ret = 0;

    ret = pthread_create(&mHandle, NULL, mFun, mArgs);
    if (ret < 0) {
        thread_log("failed to create thread %d.\n", mHandle);
        return -1;
    }
    return 0;
}

void thread::run() {
    pthread_join(mHandle, mRet);
    //pthread_detach(mHandle);
}